# Makefile for 超电CAN协议模块单元测试
# Copyright (c) TX 2025

# 编译器设置
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g -O0 -DTEST_MODE
INCLUDES = -I.

# 源文件
SOURCES = test_chaodian_can_L.c test_main_chaodian_can_L.c
TARGET = test_chaodian_can_L

# 模拟源文件（用于测试）
MOCK_SOURCES = mock_systick.c mock_can.c mock_crc.c

# 被测试的源文件
TESTED_SOURCES = srv_chaodian_can_L.c

# 目标文件
OBJECTS = $(SOURCES:.c=.o) $(MOCK_SOURCES:.c=.o) $(TESTED_SOURCES:.c=.o)

# 默认目标
all: $(TARGET)

# 编译目标
$(TARGET): $(OBJECTS)
	@echo "链接测试程序..."
	$(CC) $(OBJECTS) -o $(TARGET)
	@echo "测试程序编译完成: $(TARGET)"

# 编译规则
%.o: %.c
	@echo "编译 $<..."
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# 运行测试
test: $(TARGET)
	@echo "运行单元测试..."
	./$(TARGET)

# 运行特定测试套件
test-basic: $(TARGET)
	@echo "运行基础函数测试..."
	./$(TARGET) basic

test-transform: $(TARGET)
	@echo "运行数据转换测试..."
	./$(TARGET) transform

test-register: $(TARGET)
	@echo "运行寄存器操作测试..."
	./$(TARGET) register

test-message: $(TARGET)
	@echo "运行消息处理测试..."
	./$(TARGET) message

test-upgrade: $(TARGET)
	@echo "运行升级功能测试..."
	./$(TARGET) upgrade

test-integration: $(TARGET)
	@echo "运行集成测试..."
	./$(TARGET) integration

# 运行性能测试
perf: $(TARGET)
	@echo "运行性能测试..."
	./$(TARGET) performance

# 运行压力测试
stress: $(TARGET)
	@echo "运行压力测试..."
	./$(TARGET) stress

# 清理
clean:
	@echo "清理编译文件..."
	rm -f $(OBJECTS) $(TARGET)
	@echo "清理完成"

# 帮助信息
help:
	@echo "超电CAN协议模块单元测试 Makefile"
	@echo ""
	@echo "可用目标:"
	@echo "  all          - 编译测试程序"
	@echo "  test         - 运行所有测试"
	@echo "  test-basic   - 运行基础函数测试"
	@echo "  test-transform - 运行数据转换测试"
	@echo "  test-register - 运行寄存器操作测试"
	@echo "  test-message  - 运行消息处理测试"
	@echo "  test-upgrade  - 运行升级功能测试"
	@echo "  test-integration - 运行集成测试"
	@echo "  perf         - 运行性能测试"
	@echo "  stress       - 运行压力测试"
	@echo "  clean        - 清理编译文件"
	@echo "  help         - 显示此帮助信息"
	@echo ""
	@echo "示例:"
	@echo "  make test-basic"
	@echo "  make perf"
	@echo "  make clean"

# 声明伪目标
.PHONY: all test test-basic test-transform test-register test-message test-upgrade test-integration perf stress clean help
